home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / J A V A / Java Development Kit V1.2 / jdk12-win32(1).exe / data1.cab / demos / demo / jfc / SwingSet / DirectionButton.java < prev    next >
Encoding:
Java Source  |  1998-12-01  |  5.9 KB  |  119 lines

  1. /*
  2.  * @(#)DirectionButton.java    1.6 98/08/26
  3.  *
  4.  * Copyright 1997, 1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. import javax.swing.*;
  16. import javax.swing.border.*;
  17.  
  18. import java.awt.*;
  19. import java.awt.event.*;
  20. import java.util.*;
  21.  
  22.  
  23. /**
  24.  * @version 1.6 08/26/98
  25.  * @author Jeff Dinkins
  26.  */ 
  27. public class DirectionButton extends JRadioButton {
  28.  
  29.     // Chester's way cool layout buttons 
  30.     public static ImageIcon bl_dot   = SwingSet.sharedInstance().loadImageIcon("images/layout/bl.gif","bottom left layout button");
  31.     public static ImageIcon bldn_dot = SwingSet.sharedInstance().loadImageIcon("images/layout/bldn.gif","selected bottom left layout button");
  32.     public static ImageIcon bm_dot   = SwingSet.sharedInstance().loadImageIcon("images/layout/bm.gif","bottom middle layout button");
  33.     public static ImageIcon bmdn_dot = SwingSet.sharedInstance().loadImageIcon("images/layout/bmdn.gif","selected bottom middle layout button");
  34.     public static ImageIcon br_dot   = SwingSet.sharedInstance().loadImageIcon("images/layout/br.gif","bottom right layout button");
  35.     public static ImageIcon brdn_dot = SwingSet.sharedInstance().loadImageIcon("images/layout/brdn.gif","selected bottom right layout button");
  36.     public static ImageIcon c_dot    = SwingSet.sharedInstance().loadImageIcon("images/layout/c.gif","center layout button");
  37.     public static ImageIcon cdn_dot  = SwingSet.sharedInstance().loadImageIcon("images/layout/cdn.gif","selected center layout button");
  38.     public static ImageIcon ml_dot   = SwingSet.sharedInstance().loadImageIcon("images/layout/ml.gif","middle left layout button");
  39.     public static ImageIcon mldn_dot = SwingSet.sharedInstance().loadImageIcon("images/layout/mldn.gif","selected middle left layout button");
  40.     public static ImageIcon mr_dot   = SwingSet.sharedInstance().loadImageIcon("images/layout/mr.gif","middle right layout button");
  41.     public static ImageIcon mrdn_dot = SwingSet.sharedInstance().loadImageIcon("images/layout/mrdn.gif","selected middle right layout button");
  42.     public static ImageIcon tl_dot   = SwingSet.sharedInstance().loadImageIcon("images/layout/tl.gif","top left layout button");
  43.     public static ImageIcon tldn_dot = SwingSet.sharedInstance().loadImageIcon("images/layout/tldn.gif","selected top left layout button");
  44.     public static ImageIcon tm_dot   = SwingSet.sharedInstance().loadImageIcon("images/layout/tm.gif","top middle layout button");
  45.     public static ImageIcon tmdn_dot = SwingSet.sharedInstance().loadImageIcon("images/layout/tmdn.gif","selected top middle layout button");
  46.     public static ImageIcon tr_dot   = SwingSet.sharedInstance().loadImageIcon("images/layout/tr.gif","top right layout button");
  47.     public static ImageIcon trdn_dot = SwingSet.sharedInstance().loadImageIcon("images/layout/trdn.gif","selected top right layout button");
  48.  
  49.     
  50.     /**
  51.      * A layout direction button
  52.      */
  53.     public DirectionButton(Icon icon, Icon downIcon, String direction,
  54.                String description, ActionListener l, 
  55.                ButtonGroup group, boolean selected)
  56.     {
  57.     super();
  58.     setSelected(selected);
  59.     this.addActionListener(l);
  60.     setFocusPainted(false);
  61.     setHorizontalTextPosition(CENTER);
  62.     group.add(this);
  63.     setIcon(icon);
  64.     setSelectedIcon(downIcon);
  65.     setActionCommand(direction);
  66.     getAccessibleContext().setAccessibleName(direction);
  67.     getAccessibleContext().setAccessibleDescription(description);
  68.     }
  69.  
  70.     public boolean isFocusTraversable() {
  71.         return false;
  72.     }
  73.  
  74.     public void setBorder(Border b) {
  75.     }
  76.  
  77.  
  78.     public static JPanel createDirectionPanel(boolean enable, String selected, ActionListener l) {
  79.     JPanel p = SwingSet.createVerticalPanel(false);
  80.     p.setAlignmentY(TOP_ALIGNMENT);
  81.     p.setAlignmentX(LEFT_ALIGNMENT);
  82.  
  83.     Box firstThree = Box.createHorizontalBox();
  84.     Box secondThree = Box.createHorizontalBox();
  85.     Box thirdThree = Box.createHorizontalBox();
  86.  
  87.     if(!enable) {
  88.         selected = "None";
  89.     }
  90.  
  91.     ButtonGroup group = new ButtonGroup();
  92.     DirectionButton b;
  93.     b = (DirectionButton) firstThree.add(new DirectionButton(  tl_dot, tldn_dot, "NW", "Sets the orientation to the North-West", l, group, selected.equals("NW")));
  94.     b.setEnabled(enable);
  95.     b = (DirectionButton) firstThree.add(new DirectionButton(  tm_dot, tmdn_dot, "N",  "Sets the orientation to the North", l, group, selected.equals("N")));
  96.     b.setEnabled(enable);
  97.     b = (DirectionButton) firstThree.add(new DirectionButton(  tr_dot, trdn_dot, "NE", "Sets the orientation to the North-East", l, group, selected.equals("NE")));
  98.     b.setEnabled(enable);
  99.     b = (DirectionButton) secondThree.add(new DirectionButton( ml_dot, mldn_dot, "W", "Sets the orientation to the West", l, group, selected.equals("W")));
  100.     b.setEnabled(enable);
  101.     b = (DirectionButton) secondThree.add(new DirectionButton( c_dot,  cdn_dot,  "C", "Sets the orientation to the Center", l, group, selected.equals("C")));
  102.     b.setEnabled(enable);
  103.     b = (DirectionButton) secondThree.add(new DirectionButton( mr_dot, mrdn_dot, "E", "Sets the orientation to the East", l, group, selected.equals("E")));
  104.     b.setEnabled(enable);
  105.     b = (DirectionButton) thirdThree.add(new DirectionButton(  bl_dot, bldn_dot, "SW", "Sets the orientation to the South-West", l, group, selected.equals("SW")));
  106.     b.setEnabled(enable);
  107.     b = (DirectionButton) thirdThree.add(new DirectionButton(  bm_dot, bmdn_dot, "S", "Sets the orientation to the South", l, group, selected.equals("S")));
  108.     b.setEnabled(enable);
  109.     b = (DirectionButton) thirdThree.add(new DirectionButton(  br_dot, brdn_dot, "SE", "Sets the orientation to the South-East", l, group, selected.equals("SE")));
  110.     b.setEnabled(enable);
  111.  
  112.     p.add(firstThree);
  113.     p.add(secondThree);
  114.     p.add(thirdThree);
  115.     
  116.     return p;
  117.     }
  118. }
  119.